<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="会员编号" prop="memberId">-->
<!--      <el-input v-model="dataForm.memberId" placeholder="会员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="会员编号" prop="memberId">
        <el-select v-model="dataForm.memberId" placeholder="请选择">
          <el-option v-for="(item,i) in memberModel" :label="item.memberNameConcatId" :value="item.memberId"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="来访者姓名" prop="comeinName">
      <el-input v-model="dataForm.comeinName" placeholder="来访者姓名"></el-input>
    </el-form-item>
    <el-form-item label="来访者电话" prop="comeinPhone">
      <el-input v-model="dataForm.comeinPhone" placeholder="来访者电话"></el-input>
    </el-form-item>
      <el-form-item label="来访人员类型" prop="comeinType">
        <el-select v-model="dataForm.comeinType" placeholder="请选择">
          <el-option label="家属" value="家属"></el-option>
          <el-option label="亲戚" value="亲戚"></el-option>
          <el-option label="朋友" value="朋友"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否预约" prop="comeinIforder">
        <el-select v-model="dataForm.comeinIforder" placeholder="请选择">
          <el-option label="是" value="是"></el-option>
          <el-option label="否" value="否"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="来访状态" prop="comeinState">
        <el-select v-model="dataForm.comeinState" placeholder="请选择">
          <el-option label="未离开" value="未离开"></el-option>
          <el-option label="已离开" value="已离开"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="来访缘由" prop="comeinReason">
      <el-input v-model="dataForm.comeinReason" placeholder="来访缘由"></el-input>
    </el-form-item>
    <el-form-item label="同行人数" prop="comeinNum">
      <el-input v-model="dataForm.comeinNum" placeholder="同行人数"></el-input>
    </el-form-item>
      <el-form-item label="预约来访时间" prop="comeinOrdertime">
        <el-date-picker
          v-model="dataForm.comeinOrdertime"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="实际来访时间" prop="comeinFacttime">
        <el-date-picker
          v-model="dataForm.comeinFacttime"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="离开时间" prop="comeinOuttime">
        <el-date-picker
          v-model="dataForm.comeinOuttime"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="comeinNote">
        <el-input v-model="dataForm.comeinNote" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    created () {
      this.getMemberInfo()
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          comeinName: '',
          comeinPhone: '',
          comeinType: '',
          comeinIforder: '',
          comeinState: '',
          comeinReason: '',
          comeinNum: '',
          comeinNote: '',
          comeinOrdertime: '',
          comeinFacttime: '',
          comeinOuttime: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '会员编号不能为空', trigger: 'blur' }
          ],
          comeinName: [
            { required: true, message: '来访者姓名不能为空', trigger: 'blur' }
          ],
          comeinPhone: [
            { required: true, message: '来访者电话不能为空', trigger: 'blur' }
          ],
          comeinType: [
            { required: true, message: '来访人员类型不能为空', trigger: 'blur' }
          ],
          comeinIforder: [
            { required: true, message: '是否预约不能为空', trigger: 'blur' }
          ],
          comeinState: [
            { required: true, message: '来访状态不能为空', trigger: 'blur' }
          ],
          comeinReason: [
            { required: true, message: '来访缘由不能为空', trigger: 'blur' }
          ],
          comeinNum: [
            { required: true, message: '同行人数不能为空', trigger: 'blur' }
          ],
          comeinNote: [
            // { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          comeinOrdertime: [
            { required: true, message: '预约来访时间不能为空', trigger: 'blur' }
          ],
          comeinFacttime: [
            { required: true, message: '实际来访时间不能为空', trigger: 'blur' }
          ],
          comeinOuttime: [
            { required: true, message: '离开时间不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        },
        memberModel: {
          memberId: '',
          memberNameConcatId: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_regiscomein/bsregiscomein/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.bsRegiscomein.memberId
                this.dataForm.comeinName = data.bsRegiscomein.comeinName
                this.dataForm.comeinPhone = data.bsRegiscomein.comeinPhone
                this.dataForm.comeinType = data.bsRegiscomein.comeinType
                this.dataForm.comeinIforder = data.bsRegiscomein.comeinIforder
                this.dataForm.comeinState = data.bsRegiscomein.comeinState
                this.dataForm.comeinReason = data.bsRegiscomein.comeinReason
                this.dataForm.comeinNum = data.bsRegiscomein.comeinNum
                this.dataForm.comeinNote = data.bsRegiscomein.comeinNote
                this.dataForm.comeinOrdertime = data.bsRegiscomein.comeinOrdertime
                this.dataForm.comeinFacttime = data.bsRegiscomein.comeinFacttime
                this.dataForm.comeinOuttime = data.bsRegiscomein.comeinOuttime
                this.dataForm.createTime = data.bsRegiscomein.createTime
                this.dataForm.updateTime = data.bsRegiscomein.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_regiscomein/bsregiscomein/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'comeinName': this.dataForm.comeinName,
                'comeinPhone': this.dataForm.comeinPhone,
                'comeinType': this.dataForm.comeinType,
                'comeinIforder': this.dataForm.comeinIforder,
                'comeinState': this.dataForm.comeinState,
                'comeinReason': this.dataForm.comeinReason,
                'comeinNum': this.dataForm.comeinNum,
                'comeinNote': this.dataForm.comeinNote,
                'comeinOrdertime': this.dataForm.comeinOrdertime,
                'comeinFacttime': this.dataForm.comeinFacttime,
                'comeinOuttime': this.dataForm.comeinOuttime,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      //获取会员信息下拉
      getMemberInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllMember`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.memberModel = data.date
          }
        })
      }
    }
  }
</script>
